package com.ycu.jk16.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ycu.jk16.mall.dao.CategoryDao;
import com.ycu.jk16.mall.dao.ParentCategoryDao;
import com.ycu.jk16.mall.domain.Category;
import com.ycu.jk16.mall.domain.ParentCategory;
import com.ycu.jk16.mall.service.CategoryService;

@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {
	/**
	 * 注入持久层对象
	 */
	@Autowired
	private CategoryDao categoryDao;
	@Autowired
	private ParentCategoryDao parentCategoryDao;

	@Override
	public void addCategory(Integer parentCategoryId, String name) {
		categoryDao.addCategory(parentCategoryId, name);
	}

	@Override
	public void updateName(Category category) {
		categoryDao.updateCategoryName(category);
	}

	@Override
	public List<Category> getDeepCategory(Integer parentCategoryId) {
		return categoryDao.selectAllById(parentCategoryId);
	}

	@Override
	public Category findCategoryById(Integer id) {
		return categoryDao.selectById(id);
	}

	@Override
	public void addParentCategory(String name) {
		parentCategoryDao.addParentCategory(name);
	}

	@Override
	public void updateParentCategory(Integer id, String name) {
		parentCategoryDao.updateParentCategory(id, name);
	}

	@Override
	public ParentCategory findParentCategoryById(Integer id) {
		return parentCategoryDao.selectById(id);
	}

	@Override
	public List<ParentCategory> getParentCategorieList() {
		return parentCategoryDao.getAllParentCategory();
	}

	@Override
	public ParentCategory findParentCategoryByName(String name) {
		return parentCategoryDao.selectByName(name);
	}

	@Override
	public List<Category> getCategoriesByParentId(Integer parentId) {
		return categoryDao.getCategoryByParentId(parentId);
	}

}
